﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class manage_laoshi : System.Web.UI.Page
{

    
    string s_where, s_order;
    string curindex = String.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["sTittle"] = "管理课程";
        if (!IsPostBack)
        {
            DataBrid();
        }
    }


    // 李红新更改 2010-09-17 绑定数据
    private void DataBrid()
    {
        int record = 0;
        int count = 0;
        s_order = "ORDER BY [id] DESC";
        s_where = string.Format(" WHERE (([jigou] = '{0}') AND ([laoshi] = '{1}' OR [writer]='{1}'))", Session["sJigou"].ToString(), Session["sUserName"].ToString());
        Session["sqlwhere"] = s_where;
        string sqlText = "*";
        DataTable DT = DbHelper.ExecutePage(sqlText, "[kecheng]" + s_where, "id", s_order, Pager.CurrentPageIndex, Pager.PageSize, out record, out count, null);
        Pager.RecordCount = record;
        this.GridView1.DataSource = DT;
        this.GridView1.DataBind();
    }



    //李红新更改 2010-09-17 条件绑定数据
    private void DataBrid(string sqlwhere)
    {
        int record = 0;
        int count = 0;
        s_order = "ORDER BY [id] DESC";
        //s_order = "ORDER BY [xtsj2] DESC";
        string sqlText = "*";
        DataTable DT = DbHelper.ExecutePage(sqlText, "[kecheng]" + sqlwhere, "id", s_order, Pager.CurrentPageIndex, Pager.PageSize, out record, out count, null);
        Pager.RecordCount = record;
        this.GridView1.DataSource = DT;
        this.GridView1.DataBind();
    }




    protected void pager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        Pager.CurrentPageIndex = e.NewPageIndex;
        if (ViewState["sqlwhere"] != null)
        {
            DataBrid(ViewState["sqlwhere"].ToString());
        }
        else
        {
            DataBrid();
        }

    }



     protected void Button2_Click(object sender, EventArgs e)
     {
         if (GridView1.Rows.Count > 0)
         {
             string sql = string.Empty;
             for (int i = 0; i < GridView1.Rows.Count; i++)
             {
                 if (((CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1")).Checked)
                 {
                     sql += string.Format(" id={0} or ", GridView1.Rows[i].Cells[1].Text);
                 }
             }
             if (sql != string.Empty)
             {
                 sql = sql.Substring(0, sql.Length - 4);
                 sql = string.Format("delete from kecheng where {0}", sql);
                 int num = DbHelper.ExecuteNonQuery(CommandType.Text, sql, null);
                 if (num > 0)
                 {
                     Response.Write(string.Format("<script language='javascript'>alert('{0}');window.location.href='kecheng_manage_laoshi.aspx'</script>", "删除成功"));
                     DataBrid();
                 }
                 else
                 {
                     Response.Write(string.Format("<script language='javascript'>alert('{0}');</script>", "删除失败"));
                 }
             }
             else
             {
                 Response.Write(string.Format("<script language='javascript'>alert('{0}');</script>", "请选择欲删除的课程"));
             }
         }
     }
     protected void btnSearch_Click(object sender, EventArgs e)
     {
         string strWhere = Session["sqlwhere"].ToString();
        if (!string.IsNullOrEmpty(txtKecheng1.Text))
        {
            strWhere += " and name like '%" + txtKecheng1.Text + "%'";
        }
        if (!string.IsNullOrEmpty(typeList.SelectedValue))
        {
            strWhere += " and kechenglx='" + typeList.SelectedValue + "'";
        }
        if (!string.IsNullOrEmpty(statusList.SelectedValue))
        {
            strWhere += " and confirm='" + statusList.SelectedValue + "'";
        }
        if (!string.IsNullOrEmpty(StartDate.Value))
        {
            strWhere += " and xtsj2 >='" + StartDate.Value + "'";
        }
        if (!string.IsNullOrEmpty(EndDate.Value))
        {
            strWhere += " and xtsj2 <'" + EndDate.Value + "'";
        }
        if (strWhere != Session["sqlwhere"].ToString())
        {
            Pager.CurrentPageIndex = 0;
            DataBrid(strWhere);
            ViewState["sqlwhere"] = strWhere;
        }
        else
        {
            Pager.CurrentPageIndex = 0;
            DataBrid();
        }
     }
}
